import 'package:flutter/material.dart';
import '../Gloabal.dart';
import 'package:flutter/services.dart' show rootBundle;

List<String> ParseGlobalFilePaths(){
  List<String> allPaths = [];
  for (var entry in GlobalSettings.FilePath) {
    entry.forEach((key, value) {
      allPaths.addAll(value);
    });
  }
  return allPaths.toSet().toList(); // 去重
}

Future<List<String>> searchAssets(List<String> assetPaths, String keyword) async {
  final reg = RegExp(r'' + RegExp.escape(keyword), caseSensitive: false);
  List<String> result = [];
  var is_valid = false;
  for (var path in assetPaths) {
    try {
      final content = await rootBundle.loadString(path);
      if (reg.hasMatch(content)) {
        result.add('文件 $path 包含关键词"$keyword"');
        is_valid = true;
      }
    } catch (e) {
      result.add('读取文件 $path 失败：$e');
    }
  }
  if(!is_valid) result.add("未找到相关文件");
  return result;
}